//
//  WBHomeViewController.swift
//  盈微博
//
//  Created by hoterzhang on 2018/1/20.
//  Copyright © 2018年 hoterzhang. All rights reserved.
//

import UIKit

// 定义全局常量 尽量使用private
private let  cellId = "CELLID"

class WBHomeViewController: WBBaseViewController {

//    override func viewDidLoad() {
//        super.viewDidLoad()
//        setupUI()
//
//    }
    
    private lazy var statusList = [String]()
    
    // 加载数据
    override func loadData() {
        for i in 0...10 {
            statusList.insert(i.description, at: 0)
        }
    }

    override func setupUI() {
        setupHomeUI()
        super.setupUI()
    }
    
    @objc private func showFriends(){
        print("show friends")
        let vc = WBDemoViewController()
        vc.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(vc, animated: true)
    }

}
// MARK: - 表格数据源方法
extension WBHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //注册原形的cell
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
        //1 取cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        //2 设置cell
        cell.textLabel?.text = statusList[indexPath.row]
        //3 返回cell
        return cell
    }
}

extension WBHomeViewController {
    
    private func setupHomeUI(){
        //无法高亮
        //navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(showFriends))
        // 可以高亮
//        let btn: UIButton = UIButton.cz_textButton("好友", fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
//        btn.addTarget(self, action: #selector(showFriends), for: .touchUpInside)
//        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        //使用自定义
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
          navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        
    }
}
